package org.ysu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ysu.core.YsuException;
import org.ysu.mapper.AnalyseMapper;
import org.ysu.service.AnalyseService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author breeze
 * @date 2024/8/28 14:33
 */
@Service
public class AnalyseServiceImpl implements AnalyseService {
    @Resource
    private AnalyseMapper analyseMapper;
    @Override
    public List<Long> getRiskNum(Integer provinceCode) {
        Map<String, Long> resultMap = analyseMapper.getRiskTypeCounts(provinceCode);

        List<Long> riskTypeCounts = new ArrayList<>();
        riskTypeCounts.add(resultMap.get("type1Count"));
        riskTypeCounts.add(resultMap.get("type2Count"));
        riskTypeCounts.add(resultMap.get("type3Count"));
        riskTypeCounts.add(resultMap.get("type4Count"));
        riskTypeCounts.add(resultMap.get("type5Count"));

        return riskTypeCounts;
    }

    @Override
    public List<Map<Integer, Integer>> getPoorTotalDistribution(Integer districtCode, String districtType) {
        switch (districtType){
            case "0":
                return analyseMapper.getPoorTotalProvinceDistribution(districtCode);
            case "1":
                return analyseMapper.getPoorTotalCityDistribution(districtCode);
            case "2":
                return analyseMapper.getPoorTotalAreaDistribution(districtCode);
        }
        throw new YsuException("找不到对应的查询深度");
    }

    @Override
    public List<Map<Integer, Integer>> getPoorRiskDistribution(Integer districtCode, String districtType) {
        switch (districtType){
            case "0":
                return analyseMapper.getPoorRiskProvinceDistribution(districtCode);
            case "1":
                return analyseMapper.getPoorRiskCityDistribution(districtCode);
            case "2":
                return analyseMapper.getPoorRiskAreaDistribution(districtCode);
        }
        throw new YsuException("找不到对应的查询深度");
    }

    @Override
    public List<Map<Integer, Integer>> getPoorClueDistribution(Integer districtCode, String districtType) {
        switch (districtType){
            case "0":
                return analyseMapper.getPoorClueProvinceDistribution(districtCode);
            case "1":
                return analyseMapper.getPoorClueCityDistribution(districtCode);
            case "2":
                return analyseMapper.getPoorClueAreaDistribution(districtCode);
        }
        throw new YsuException("找不到对应的查询深度");
    }
}
